package com.dididoctor.patient.Activity.Doctor;

import android.content.Context;

import com.dididoctor.patient.Activity.ConstantValue;
import com.dididoctor.patient.Bean.Token;
import com.dididoctor.patient.Http.MyHttpResponseHandler;
import com.dididoctor.patient.MV.BasePresenter;
import com.dididoctor.patient.MV.BusinessClient;
import com.dididoctor.patient.MV.Response;
import com.dididoctor.patient.Utils.Util;
import com.loopj.android.http.RequestParams;

import org.apache.http.Header;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @version 2.0
 * @类描述： 登陆页
 * @项目名称：ddgh
 * @类名称： loginActivity
 * @包名称： com.doudoukeji.service.Activity.login
 * @创建人：张强 boy
 * @创建时间：2016/3/7 16:40
 * @修改人：
 * @修改时间：2016/3/7 16:40
 * @修改备注： new parent class(用一句话描述修改了什么)
 */
public class ForumPresenter extends BasePresenter {
    private ForumView view;

    public ForumPresenter(Context context, ForumView view) {
        super(context, view);
        this.view = view;
    }

    /**
     * @param longitude 经度
     * @param latitude  维度
     * @param isOnline  是否在线 1在 0不在
     * @param pageIndex
     */
    public void getdoctordata(String longitude, String latitude, String isOnline, int pageIndex, String cityCode, String doctorName) {
        RequestParams params = new RequestParams();
        params.put("longitude", longitude);
        params.put("latitude", latitude);
        params.put("isOnline", isOnline);
        params.put("pageIndex", Util.toString(pageIndex));
        params.put("userId", Token.getId());
        params.put("pageSize", "10");
        params.put("cityCode", cityCode);
        params.put("token", Token.getToken());
        params.put("doctorName", doctorName);
        BusinessClient.post(ConstantValue.doctorList, params, new MyHttpResponseHandler() {
            private List<Doctor> doctors = new ArrayList<Doctor>();
            private List<Map<String, String>> maps = new ArrayList<Map<String, String>>();

            @Override
            public void onMyResponse(Response response) {
                if (response.isSucceed()) {
                    maps = response.getListData("doctorList");
                    for (Map<String, String> map : maps) {
                        Doctor doctor = new Doctor();
                        doctor.setOnline(Util.toString(map.get("online")));
                        doctor.setCallSwitch(Util.toString(map.get("callSwitch")));
                        doctor.setDoctorId(Util.toString(map.get("doctorId")));
                        doctor.setHospitalId(Util.toString(map.get("hospitalId")));
                        doctor.setHeadPic(Util.toString(map.get("headPic")));
                        doctor.setName(Util.toString(map.get("name")));
                        doctor.setHospital(Util.toString(map.get("hospital")));
                        doctor.setEvaluate(Util.toString(map.get("evaluate")));
                        doctor.setSignNum(Util.toString(map.get("signNum")));
                        doctor.setPosition(Util.toString(map.get("position")));
                        doctor.setDistance(Util.toString(map.get("distance")));
                        doctor.setIsSign(Util.toString(map.get("isSign")));
                        doctors.add(doctor);
                    }
                    view.getdoctorsucced(doctors);
                } else {
                    view.getdoctorsucced(doctors);
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
                super.onFailure(i, headers, bytes, throwable);
                view.getdoctorfail();
            }
        });
    }

}
